﻿using System;
using System.Diagnostics;
using System.Threading;

namespace NTTDATA.BEENChina.CaseMonitor.ServerChecker
{
    [Serializable]
    public abstract class Server
    {

        private ServerState serverState
        {
            get;
            set;
        }

        
        public String Address
        {
            get;
            set;
        }

        public String Name 
        { 
            get; 
            set; 
        }

        public String DBName { get; set; }

        public String UserId { get; set; }

        public String PassWord { get; set; }

        public String LogDBName { get; set; }

        public virtual ServerState IsRunning()
        {
            try
            {
                bool running = CheckRunnint();

                serverState = running ? ServerState.Running : ServerState.Stop;
            }
            catch (Exception ex)
            {
                
                Log.Console.Error("Server.IsRunning()",ex);
            }
            return serverState;
        }

        protected abstract bool CheckRunnint();


        public String WorkState()
        {
            return serverState.ToString();
        }

        private bool IsConnect()
        {
            string ipAddress = this.Address;
            int splitIndex = Address.IndexOf('\\');
            if (splitIndex > 0)
            {
                ipAddress = ipAddress.Substring(0, splitIndex);
            }

            return NetWork.NetWork.Ping(ipAddress);
        }

        
    }
}